package aitsm;
import java.awt.HeadlessException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;

public class Create_account extends javax.swing.JFrame {
    XMLConfig c = new XMLConfig();
    Connect_class ConnClass = new Connect_class();
    LoginStaff cLogin = new LoginStaff();
    ProcessPublic proPublic = new ProcessPublic();
    public Create_account() {
        initComponents();
   
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        Panel_Create_new_acc = new javax.swing.JPanel();
        Label_logo1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cbTechnology = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        txtStaff_id = new javax.swing.JTextField();
        jButton14 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtFirstName = new javax.swing.JTextField();
        txtAddress = new javax.swing.JTextField();
        txtLastName = new javax.swing.JTextField();
        cbGender = new javax.swing.JComboBox();
        txtPhone = new javax.swing.JTextField();
        btnCancel = new javax.swing.JButton();
        cbRule = new javax.swing.JComboBox();
        jDate = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        txtPersonal = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel13 = new javax.swing.JLabel();
        cbStaff_ID = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableSubject_Staff = new javax.swing.JTable();
        cbStaff_State = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(778, 338));
        setResizable(false);

        Label_logo1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        Label_logo1.setForeground(new java.awt.Color(51, 0, 102));
        Label_logo1.setText("Create new account");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel4.setText("Technology name:");

        cbTechnology.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        cbTechnology.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTechnologyActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel5.setText("First name:");

        txtStaff_id.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jButton14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton14.setText("Save");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel6.setText("Last name:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel7.setText("Staff ID:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel8.setText("Birthday:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel9.setText("Gender:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel10.setText("Address:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel11.setText("Phone number:");

        txtFirstName.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        txtAddress.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        txtLastName.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        cbGender.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        cbGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Fee Male" }));

        txtPhone.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        btnCancel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        cbRule.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        cbRule.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  Staff", "Admin" }));
        cbRule.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbRuleItemStateChanged(evt);
            }
        });
        cbRule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbRuleActionPerformed(evt);
            }
        });

        jDate.setDateFormatString("yyyy-MM-dd");
        jDate.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel1.setText("Password:");

        txtPersonal.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtPersonal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPersonalActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel2.setText("Personal_ID:");

        jPasswordField1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel13.setText("Subject:");

        cbStaff_ID.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        cbStaff_ID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbStaff_IDActionPerformed(evt);
            }
        });

        jTableSubject_Staff.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTableSubject_Staff.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTableSubject_Staff);

        cbStaff_State.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        cbStaff_State.setText("does not work anymore");

        javax.swing.GroupLayout Panel_Create_new_accLayout = new javax.swing.GroupLayout(Panel_Create_new_acc);
        Panel_Create_new_acc.setLayout(Panel_Create_new_accLayout);
        Panel_Create_new_accLayout.setHorizontalGroup(
            Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                                .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel13)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(87, 87, 87)
                                .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                                        .addGap(38, 38, 38)
                                        .addComponent(cbRule, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel6)
                                            .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(txtLastName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                                                .addComponent(txtFirstName, javax.swing.GroupLayout.Alignment.LEADING))
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel5)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel1)
                                            .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(112, 112, 112)
                                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel8)
                                            .addComponent(cbGender, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel2)
                                            .addComponent(txtPersonal, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel11)
                                            .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel9)
                                            .addComponent(jDate, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(cbStaff_State, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                                        .addComponent(cbStaff_ID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txtStaff_id, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(Label_logo1)))
                            .addComponent(cbTechnology, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 16, Short.MAX_VALUE))
                    .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        Panel_Create_new_accLayout.setVerticalGroup(
            Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Label_logo1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbRule)
                .addGap(22, 22, 22)
                .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbTechnology, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbStaff_ID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStaff_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel9)
                            .addComponent(jLabel1))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Panel_Create_new_accLayout.createSequentialGroup()
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel5))
                        .addGap(13, 13, 13)
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPersonal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(Panel_Create_new_accLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(cbStaff_State)
                .addGap(18, 18, 18)
                .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Panel_Create_new_acc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Panel_Create_new_acc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
private boolean blFlag = false;
private boolean blFlag_cbStaffID = false;
private Object listgender [] = {"Fee Male","Male"};
private Object listRules [] = {"Admin","Staff"}; 
private Object listRuless [] = {"Staff","Admin"};
public static  ArrayList<Integer>  tbSubject_staff = new ArrayList<>();
    private void cbStaff_IDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStaff_IDActionPerformed
        // TODO add your handling code here:
        
        try {
            if (blFlag) {
                String sStaff_id = Main_Screen.alStaff_id.get(cbStaff_ID.getSelectedIndex());
                updateStaff(sStaff_id);
                }else{  
                    String sStaff_id = Main_Screen.alStaff_id.get(0);
                    updateStaff(sStaff_id);
                     blFlag = true;
                }
            
        } catch (Exception e) {
        }
        
        
    }//GEN-LAST:event_cbStaff_IDActionPerformed

    private void txtPersonalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPersonalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPersonalActionPerformed

    private void cbTechnologyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTechnologyActionPerformed
        // TODO add your handling code here:
        if (Main_Screen.flag_Staff == "add") {
            String sql_subject = "select subject_name from subject s left outer join techology t on s.technology_id = t.technology_id " + 
                                " where t.technology_name = '"+ cbTechnology.getSelectedItem() +"'";
            
            ResultSet rs = ConnClass.getRecordSet(sql_subject);
            proPublic.JTableCheckBoxRecordSet(jTableSubject_Staff, rs);
        }
        if ("up".equals(Main_Screen.flag_Staff)) {
            try {

                String sql_Subject ="select s.subject_name from subject s " +
                                        "left outer join staff_subject ss on ss.subject_id = s.subject_id "+
                                        "left outer join staff st on st.staff_id = ss.staff_id "+
                                        "where st.staff_id = '"+cbStaff_ID.getSelectedItem()+"'";
                
                ResultSet rsSubject = ConnClass.getRecordSet(sql_Subject);
                ArrayList<String> alSubject = new ArrayList<>();
                int i=0;
                
                String alS ="";
                while(rsSubject.next()) {
                    alSubject.add(rsSubject.getString("subject_name"));
                    i = i + 1;
                }
                jTableSubject_Staff.removeAll();
                String sql_subjectcheck = "select subject_name from subject s left outer join techology t on s.technology_id = t.technology_id " + 
                                    " where t.technology_name = '"+ cbTechnology.getSelectedItem() +"'";
                ResultSet rs_check = ConnClass.getRecordSet(sql_subjectcheck);
                proPublic.JTableCheckBoxRecordSet(jTableSubject_Staff, rs_check);
//unemployed working
                
                for (int j = 0; j <= jTableSubject_Staff.getRowCount(); j++) {
//                        System.out.println("co: " +  j);
                        for (int k = 0; k < i; k++) {
                            if (alSubject.get(k).equals(jTableSubject_Staff.getValueAt(j, 0).toString())) {
                                jTableSubject_Staff.setValueAt(true, j, 1);
//                                System.out.println("aaaaaaaa");
                            }
                        }
                    }
                } catch (Exception e) {
            }
        }
        
    }//GEN-LAST:event_cbTechnologyActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        // TODO add your handling code here:
        if ("add".equals(Main_Screen.flag_Staff)) {
            insertStaff();
        }
        if ("up".equals(Main_Screen.flag_Staff)) {
//            updateStaff();
        }

        
    }//GEN-LAST:event_jButton14ActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        
//        LoadfromStaff();
        this.setVisible(false);
        if (cLogin.rule) {
//            Staff
        }else{
//            Admin 
            cLogin.showStaffAdmin();            
                for (int i = 0; i < Main_Screen.alStaff_id.size(); ) {
                    Main_Screen.alStaff_id.remove(i);
                }

        }
    
    }//GEN-LAST:event_btnCancelActionPerformed

    private void cbRuleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbRuleActionPerformed
        // TODO add your handling code here:
//        System.out.println(cbRule.getSelectedItem());
        if (!blFlag_cbStaffID) {
             if (cbRule.getSelectedItem().equals("Admin")) {
                cbTechnology.setEnabled(false);
                jTableSubject_Staff.setEnabled(false);
                
            } else{
                cbTechnology.setEnabled(true);
                jTableSubject_Staff.setEnabled(true);
                String SQL_tech = "Select technology_name From techology";
                ResultSet rs_tech = ConnClass.getRecordSet(SQL_tech);
                proPublic.JCompoBoxRecordSet(cbTechnology, rs_tech, 1);
            }
            
        }

        
    }//GEN-LAST:event_cbRuleActionPerformed
//private ArrayList <String> tbSubject_staff = new ArrayList<>();

    private void cbRuleItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbRuleItemStateChanged
        // TODO add your handling code here:
        if (Main_Screen.flag_Staff.equals("add")) {
            if (cbRule.getSelectedItem().equals("Admin")) {
            cbTechnology.setEnabled(false);
            jTableSubject_Staff.setEnabled(false);
//                String s = "";
                for (int i = 0; i < jTableSubject_Staff.getRowCount();i++) {
                    if(jTableSubject_Staff.getValueAt(i, 1) == true){
                        tbSubject_staff.add(i);
                    }
                }
                for (Integer i : tbSubject_staff) {
                    jTableSubject_Staff.setValueAt(null, i, 1);
                }
            } else{
                cbTechnology.setEnabled(true);
                jTableSubject_Staff.setEnabled(true);
                
            }
                
        }
        
    }//GEN-LAST:event_cbRuleItemStateChanged
    private void insertStaff(){
        String kq = "";
        String kq1 = "";
        String kq2 = "";
        if (cbRule.getSelectedItem().equals("Admin")) {
                try {
                Vector data = new Vector();
                data.add(txtStaff_id.getText());
                data.add(txtPersonal.getText());
                data.add(txtFirstName.getText());
                data.add(txtLastName.getText());
                data.add(jDate);

                if (cbGender.getSelectedItem() == "Male") {
                    data.add("1");
                }else{
                    data.add("0");
                }
                data.add(txtAddress.getText());
                data.add(txtPhone.getText());
//            data.add(null);//Staff_Technology_ID
                data.add("1");//Staff_State
                String SQL = "insert into staff(staff_id,personal_id,staff_first_name,staff_last_name,birthday,gender,address,phone_number,staff_state)" +
                            " values(?,?,?,?,?,?,?,?,?)";
//                System.out.println(SQL);
                kq = proPublic.insertData(SQL, data, XMLConfig.con);
                ResultSet rs = ConnClass.getRecordSet("select staff_id from staff where staff_id = '" + txtStaff_id.getText() + "' " );

                    if (rs.next()) {
                        Vector datarule = new Vector();
                        datarule.add(rs.getString(1));
                        datarule.add(jPasswordField1.getPassword());
                        datarule.add("0");// Rule_State 
                        datarule.add("0");// Rule Admin

                        String SQLRule = proPublic.getStringInsertData("[AITSM].[dbo].[Rule]");
                        kq1 = proPublic.insertData(SQLRule, datarule, XMLConfig.con);

                    }
                    if(kq != null && kq1 != null){
                        LoadfromStaff();
                        JOptionPane.showMessageDialog(null, "New Successful!", "New Account", JOptionPane.WARNING_MESSAGE); 
                    }
                } catch (SQLException | HeadlessException ex) {
                    ex.getMessage();
    //                ex.printStackTrace();
                    JOptionPane.showMessageDialog(null, "Cannot New Account!", "New Account", JOptionPane.WARNING_MESSAGE);
                }
            }else {//Staff
//            System.out.println("aaaaaaaaaa");
                try {
                    //select Technology_ID
                    //Insert STAFF, Staff_Subject and Techology
                    Vector data = new Vector();
                    data.add(txtStaff_id.getText());
                    data.add(txtPersonal.getText());
                    data.add(txtFirstName.getText());
                    data.add(txtLastName.getText());
                    data.add(proPublic.covertDate(jDate));

                    if (cbGender.getSelectedItem() == "Male") {
                        data.add("1");
                    }else{
                        data.add("0");
                    }
                    data.add(txtAddress.getText());
                    data.add(txtPhone.getText());
                    ResultSet rs_Tech = ConnClass.getRecordSet("select technology_id from techology where technology_name = '" + cbTechnology.getSelectedItem() + "' " );
                    String sTechnologyID = "";
                    if (rs_Tech.next()) {
                        sTechnologyID = rs_Tech.getString("technology_id");
                    }
    //                Vector tech = pp.getData(sTechnologyID);

                    data.add(sTechnologyID);//Technology_ID
                    data.add("1");//Col Staff_State
                    String SQL = proPublic.getStringInsertData("staff");
                    kq = proPublic.insertData(SQL, data, XMLConfig.con);
                    //new table Rule
                    ResultSet rs = ConnClass.getRecordSet("select staff_id from staff where staff_id = '" + txtStaff_id.getText() + "' " );
                    if (rs.next()) {
                        Vector datarule = new Vector();
                        datarule.add(rs.getString(1));
                        datarule.add(jPasswordField1.getPassword());
                        datarule.add("0");// Rule_State
                        datarule.add("1");// Rule Staff
                        String SQLRule = proPublic.getStringInsertData("[AITSM].[dbo].[Rule]");
                        kq1 = proPublic.insertData(SQLRule, datarule, XMLConfig.con);                    
                    }
                    String sSubName = "";
                    for (int i = 0; i < jTableSubject_Staff.getRowCount(); i++) {
                        if (jTableSubject_Staff.getValueAt(i, 1) == null) {
                            
                        }else if(jTableSubject_Staff.getValueAt(i, 1) == true){
//                            sSubName = jTableSubject_Staff.getValueAt(i, 0).toString();
                            System.out.println(sSubName);
                            ResultSet rs_subject = ConnClass.getRecordSet("select subject_id from subject where subject_name = '"+ sSubName +"' ");
                            String sSubjectID = "";
                            if(rs_subject.next()){
                                sSubjectID = rs_subject.getString("subject_id");
                            }

                                Vector dataStaff_subject = new Vector();
                                dataStaff_subject.add(sSubjectID);
                                dataStaff_subject.add(rs.getString(1));

                                String sqlStaff_s = proPublic.getStringInsertData("[AITSM].[dbo].[staff_subject]");
                                kq2 = proPublic.insertData(sqlStaff_s, dataStaff_subject, XMLConfig.con);
                        }
                    }
                    

                    if(kq != null && kq1 != null && kq2 != null){
                        LoadfromStaff();
                        JOptionPane.showMessageDialog(null, "New Successful!", "New Account", JOptionPane.WARNING_MESSAGE); 
                        }
                } catch (SQLException | HeadlessException ex) {
                    ex.getMessage();
                    JOptionPane.showMessageDialog(null, "Cannot New Account!", "New Account", JOptionPane.WARNING_MESSAGE);
    //                Logger.getLogger(Create_account.class.getName()).log(Level.SEVERE, null, ex);
                }
            }// end Staff
    }
    

    private void updateStaff(String sStaff_id){
        
        try {
            LoadfromStaff();
        
        ResultSet rs = ConnClass.getRecordSet("Select * from staff where staff_id = '"+ sStaff_id.toString() +"' ");
                if (rs.next()) {
                    personal_id = rs.getString("personal_id").toString();
                    firstname = rs.getString("staff_first_name").toString();
                    lastname = rs.getString("staff_last_name").toString();
                    birthday = rs.getString("birthday").toString() ;
                    gender = rs.getString("gender").toString()  ;
                    address = rs.getString("address").toString();

                    staff_state_SQL = rs.getString("staff_state").toString();
                    phone = rs.getString("phone_number").toString();

                    txtPersonal.setText(personal_id);
                    txtFirstName.setText(firstname);
                    txtLastName.setText(lastname);
                    txtAddress.setText(address);
                    txtPhone.setText(phone);
                    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                    Date d = df.parse(birthday);
                    jDate.setDate(d);
                    if (gender.equals("0")) {                    
                        cbGender.removeAllItems();
                        for (Object o : listgender) {
    //                        System.out.println(o);
                        cbGender.addItem(o); 
                        }                    
                    }
                    // kiem tra nghi lam hay chua 
                    if (staff_state_SQL.equals("0")) {
                        cbStaff_State.setSelected(true);
                    }
                }
                
//                end table Staff
                ResultSet rsRule = ConnClass.getRecordSet("Select *  from [Rule] where staff_id = '"+ sStaff_id +"' " );
                if (rsRule.next()) {
                    rules = rsRule.getString("rules");
                    password = rsRule.getString("password");
//                    System.out.println("pass: "+password);
//                    System.out.println("ssss: "+rules);
                    blFlag_cbStaffID = true;
                    if (blFlag_cbStaffID) {
                        if (rules.equals("0")) { 

                        cbRule.removeAllItems();
                            for (Object o : listRules) {
                            cbRule.addItem(o); 
                            }
                            cbTechnology.setEnabled(false);
                            jTableSubject_Staff.setEnabled(false);
                        }else {
                            cbRule.removeAllItems();
                            for (Object oj : listRuless) {
                                cbRule.addItem(oj); 
                            }
                            cbTechnology.setEnabled(true);
                            jTableSubject_Staff.setEnabled(true);
                        }   
                        blFlag_cbStaffID = false;
                    }
                    jPasswordField1.setText(password);
                }else{ // return sql null
//                    System.out.println("nnnnnnn");
                    jPasswordField1.setText(null);
                    blFlag_cbStaffID = true;
                    if (blFlag_cbStaffID) {
                        cbRule.removeAllItems();
                        for (Object oj : listRuless) {
                            cbRule.addItem(oj); 
                        }
                        cbTechnology.setEnabled(true);
                        jTableSubject_Staff.setEnabled(true);
                        blFlag_cbStaffID = false;
                    }
                    
                }
//                end Rule
//                techology = rs.getString("techology_id").toString();
                    String sql_Tech_Null = "select technology_name from techology ";
                    ResultSet rsTech_Null = ConnClass.getRecordSet(sql_Tech_Null);
                    cbTechnology.removeAllItems();
                    proPublic.JCompoBoxRecordSet(cbTechnology, rsTech_Null, 1);
                techology = Main_Screen.altech_id.get(cbStaff_ID.getSelectedIndex());
                System.out.println("techology: "+techology);
                if (!"NULL".equals(techology)) {
                    String sql_Tech = "select s.subject_name,t.technology_name from subject s "+
                                       " left outer join staff_subject ss on ss.subject_id = s.subject_id "+
                                       " left outer join staff st on st.staff_id = ss.staff_id "+
                                       " left outer join techology t on t.technology_id = s.technology_id "+
                                       " where st.staff_id = '"+sStaff_id+"' ";
                    ResultSet rsTech = ConnClass.getRecordSet(sql_Tech);
                    String sTech = "";
                    if (rsTech.next()) {
                        sTech = rsTech.getString("technology_name").toString();
                        System.out.println(rsTech.getString("technology_name"));
                        
                    }
                    cbTechnology.setSelectedItem(sTech);
                    
                    
                }else{
                    
                    
                }
                
                
                
                
                
                
                

                
                
        } catch (SQLException | ParseException e) {
            
        }
        
    } 
//    load from add staff blank
    private void LoadfromStaff(){
        txtStaff_id.setText(null);
        txtFirstName.setText(null);
        txtLastName.setText(null);
        txtPersonal.setText(null);
        txtPhone.setText(null);
        txtAddress.setText(null);
        jPasswordField1.setText(null);
        jDate.setDate(null);
        
    }
    public static void main(String args[]) {
      
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Create_account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Create_account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Create_account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Create_account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Create_account().setVisible(true);
            }
        });
    }
    private String staff_id ;
    private String personal_id ;
    private String firstname ;
    private String lastname ;
    private String address ;
    private String password ;
    private String techology ;
    private String birthday ;
    private String gender ;
    private String staff_state ;
    private String rules ;
    private String staff_state_SQL ;
    private String phone ;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JLabel Label_logo1;
    private javax.swing.JPanel Panel_Create_new_acc;
    private javax.swing.JButton btnCancel;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.JComboBox cbGender;
    public static javax.swing.JComboBox cbRule;
    public static javax.swing.JComboBox cbStaff_ID;
    public static javax.swing.JCheckBox cbStaff_State;
    public static javax.swing.JComboBox cbTechnology;
    private javax.swing.JButton jButton14;
    private com.toedter.calendar.JDateChooser jDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JScrollPane jScrollPane1;
    public static javax.swing.JTable jTableSubject_Staff;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JTextField txtPersonal;
    private javax.swing.JTextField txtPhone;
    public static javax.swing.JTextField txtStaff_id;
    // End of variables declaration//GEN-END:variables
//    private JDateChooser jc;
}
